package cn.tuling.innerclass;

/**
 * 静态内部类模式
 */
public class BuilderTest {
    public static void main(String[] args) {
        Product product = new Product.Builder()
                .partA("A")
                .partB("B")
                .partC("C")
                .builder();
        product.show();
    }
}


class Product {
    private final String partA;
    private final String partB;
    private final String partC;

    public Product(String partA, String partB, String partC) {
        this.partA = partA;
        this.partB = partB;
        this.partC = partC;
    }

    public void show() {
        System.out.println("Product{" +
                "partA='" + partA + '\'' +
                ", partB='" + partB + '\'' +
                ", partC='" + partC + '\'' +
                '}');
    }

    static class Builder {
        private String partA;
        private String partB;
        private String partC;

        public Builder partA(String partA) {
            this.partA = partA;
            return this;
        }

        public Builder partB(String partB) {
            this.partB = partB;
            return this;
        }

        public Builder partC(String partC) {
            this.partC = partC;
            return this;
        }

        public Product builder() {
            return new Product(partA, partB, partC);
        }
    }
}